<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <div class="box">
        点击按钮开始点名
    </div>
    <input type="button" value="开始" id="btn">
</body>
<script>
    const box = document.querySelector(".box");
    const btn = document.querySelector("#btn");

    // 名字库
    const arr = ["a","b","c","d","e","f","g","h"];
    // 0 ~ length-1

    // 准备用来记录按钮的状态
    let type = 0;
    let t;

    btn.onclick = function(){
        // 判断按钮状态，根据状态，执行功能
        if(type === 0){
            // 开始快速切换功能
            t = setInterval(()=>{
                box.innerHTML = arr[random(0, arr.length-1)];
            }, 30)
            type = 1;
            this.value = "暂停";
        }else{
            // 停止功能
            clearInterval(t);
            type = 0;
            this.value = "继续";
        }
    }


    function random(max,min){
        return Math.round(Math.random()*(max-min)+min);
    }

</script>
</html>